
import {
    toast
} from 'nc-lightapp-front';


let currentOptSelectedRows = null;

export default class DateAction {
    constructor(comp) {
        this.comp = comp;
    }

    // 打开Date弹窗
    openDateModal = (selectedRows) => {
        const {props} = this.comp;
        const {dispatch, emp} = props;
        currentOptSelectedRows = selectedRows;

        dispatch({
            type: 'emp/update',
            payload: {
                offerContentModalVisible: true
            }
        });
        
    }

    // 发送Date
    sendDate = async (selectedRows) => {
        const {props} = this.comp;
        const {dispatch, emp} = props;
        
        if(!selectedRows && currentOptSelectedRows) {
            selectedRows = currentOptSelectedRows;
        }
        //判断日期是否为空
        if(emp.beginDate == null){
            toast({
                color: 'danger',
                content: emp.language['gx6008-000210'] //请选择要入职的日期
            })
            return false;
        }
        let postData = {
            billid: selectedRows[0].values['pk_entryapply'].value,
            pk_org: emp.orgValue.refpk,
            begindate: emp.beginDate
        };
        
        try {
            let res = await dispatch({
                type: 'emp/sendDate',
                payload: {
                    postData: postData
                }
            });

            if(res.success) {
               console.log(res)
                toast({
                    color: 'success',
                    content:  emp.language['gx6008-000052'] // "操作成功"
                });
                
                dispatch({
                    type: 'emp/update',
                    payload: {
                        offerContentModalVisible: false
                
                    }
                });
                this.comp.action.tableAct.getMainTableData();
            }
        }
        catch(e) {

        }
    }
    
    // 关闭Date弹窗
    closeDateModal = () => {
        const {props} = this.comp;
        const {dispatch, emp} = props;
        currentOptSelectedRows = null;

        dispatch({
            type: 'emp/update',
            payload: {
                offerContentModalVisible: false
            }
        });
    }

    // 日期改变回调
    onChange = (value) => {
        const {props} = this.comp;
        const {dispatch, emp} = props;

        dispatch({
            type: 'emp/update',
            payload: {
                beginDate: value
            }
        });
    }

}